package com.longteng.lesson.controller;

import com.google.common.collect.Lists;
import com.longteng.lesson.po.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator
 * DATE : 2018/5/27
 * TIME : 13:35
 * PROJECT : java-lesson
 * PACKAGE : com.longteng.lesson
 *
 * @author <a href="mailto:taki@qq.com">Administrator</a>
 */
@Controller
@RequestMapping("/jqueryController")
public class JqueryController {

    @RequestMapping("/jqueryPage")
    public String jqueryPage(){
        return "jquerypage/jquerypage";
    }

    @RequestMapping(value = "/postUser")
    public @ResponseBody Map postUser(User user){
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(user.toString());
        Map map=new HashMap();
        map.put("success",true);
        map.put("code",200);
        map.put("msg","添加用户成功");
        map.put("obj",user);
        return map;
    }

    @RequestMapping("/getUserJson")
    public @ResponseBody List getUserJson(){
        List list= Lists.newArrayList();
        User user =new User();
        user.setUserName("小象");
        user.setCity("西安");
        list.add(user);
        User user1 =new User();
        user1.setUserName("小周");
        user1.setCity("北京");
        list.add(user1);
        return list;
    }
}
